import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chiffoyqc.model.*;
import org.omg.CORBA.OBJ_ADAPTER;

import javax.json.Json;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2018/7/4.
 */
public class Test {
   private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   private static Calendar calendar = Calendar.getInstance();
//    static {


//    }

    public static void main(String[] args) {
//        String[] strings = new String[]{"aa","bb","cc"};
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("param",strings);
//
//        JSONArray param = jsonObject.getJSONArray("param");
//        System.out.println(param.toString());
//        System.out.println(param.toJSONString());
//        System.out.println(Arrays.toString(param.toArray()));
//        jsonObject.put("param",param.toString());
//
//        System.out.println(JSON.toJSONString(jsonObject));

        List<Map<String,Object>> list = new LinkedList<>();
        Map<String,Object> map1 = new HashMap<>();
        map1.put("1",1);
        map1.put("2",2);
        map1.put("3",3);
        Map<String,Object> map2 = new HashMap<>();
        map2.put("4",4);
        map2.put("5",5);
        map2.put("6",6);

        list.add(map1);
        list.add(map2);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("param", JSON.toJSONString(list));
        System.out.println(jsonObject.toJSONString());

//        String s = "{\"assetDate\":\"\",\"factoryCode\":\"600102\",\"userNo\":\"\",\"customerName\":\"王旭标\",\"phoneNo\":\"\",\"customerType\":\"\",\"meterTypeId\":\"21\",\"addrDes\":\"中牟县新县城博士园东院13#2-8-03\",\"meterId\":\"91806290245902\",\"meterNo\":\"2070497743\",\"expireDate\":\"\",\"wechatNo\":\"\"}";
//        String s = null;
//        assert s != null;
//        System.out.println(s.length());

//        testMeterAdd();
//        testMeterModify();
//        testMeterSuspend();
//        testMeterDelete();
//        testRecharge();
//        testCancelRecharge();
//        testRecharge();

//        testChangeprice();
//        testBatchChangePrice();
//        testCloseValve();
//        testOpenValve();
//        testMeterData();
//        testBillingData();
//        testRealtimeData();
//        testDayUse();

//        String s = "hkc";
//
//        try {
//            MessageDigest messageDigest = MessageDigest.getInstance("md5");
//
//            byte[] digest = messageDigest.digest(s.getBytes());
//            System.out.println(Arrays.toString(digest));
//
//            StringBuffer buffer = new StringBuffer();
//            // 把每一个byte 做一个与运算 0xff;
//            for (byte b : digest) {
//                // 与运算
//                int number = b & 0xff;// 加盐
//                String str = Integer.toHexString(number);
//                if (str.length() == 1) {
//                    buffer.append("0");
//                }
//                buffer.append(str);
//            }
//
//            // 标准的md5加密后的结果
//            System.out.println(buffer.toString());
//            System.out.println(buffer.toString().length());
//
//        } catch (NoSuchAlgorithmException e) {
//            e.printStackTrace();
//        }
//
//        System.out.println(("MIGfMA0GCSqGSIb3D4HQ632qJBVHf8sxHi/fEsrapr" +
//                "wCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je" +
//                "9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QI" +
//                "DAQAB").length());
    }

    /**7.1. 表具新增*/
    private static void testMeterAdd(){
        MeterAdd meterAdd = new MeterAdd();
        meterAdd.setMeterId("0012345678");
        meterAdd.setMeterNo("1704101484");
        meterAdd.setMeterTypeId("13");
        meterAdd.setSetUpTime("2018-07-19 09:50:23");
        meterAdd.setEnableMeterReading("0");
        meterAdd.setPriceId("1");
        meterAdd.setPriceVersion("1");
        meterAdd.setPriceLadderNum("2");
        meterAdd.setEffectiveDate("2018-07-19 08:50:23");
        meterAdd.setPrice0("1.2");
        meterAdd.setPrice1("2.4");
        meterAdd.setLevel1("100");
        meterAdd.setUserNo("00001234");
        meterAdd.setCustomerType("2");
        meterAdd.setOrgId("1221");
        meterAdd.setPhoneNo("12345678901");

        String string = JSON.toJSONString(meterAdd);
        System.out.println(string);
    }

    /**7.2. 表具修改*/
    private static void testMeterModify(){
        MeterModify meterModify = new MeterModify();
        meterModify.setMeterId("0123");
        meterModify.setMeterTypeId("14");
        meterModify.setMeterNo("1704101484");
        meterModify.setUserNo("00004321");
        meterModify.setCustomerType("1");
        meterModify.setUsedQty("100");

        String string = JSON.toJSONString(meterModify);
        System.out.println(string);
        System.out.println(JSON.toJSONString(meterModify,true));
    }

    /**7.3. 表具停用*/
    private static void testMeterSuspend(){
        MeterSuspend meterSuspend = new MeterSuspend();
        meterSuspend.setMeterId("0012345678");
        meterSuspend.setFactoryCode("1221");

        String string = JSON.toJSONString(meterSuspend);
        System.out.println(string);
    }

    /**7.4. 表具恢复*/
    private static void testMeterResume(){
        MeterResume meterResume = new MeterResume();
        meterResume.setMeterId("0012345678");
        meterResume.setFactoryCode("1221");
        String string = JSON.toJSONString(meterResume);
        System.out.println(string);
    }

    /**7.5. 表具移除*/
    private static void testMeterDelete(){
        MeterDelete meterDelete = new MeterDelete();
        meterDelete.setMeterId("0012345678");
        meterDelete.setFactoryCode("1221");
        String string = JSON.toJSONString(meterDelete);
        System.out.println(string);
    }

    /**7.10. 获取表具信息*/
    private static void testMeterData(){
        List<MeterData_Req> list = new LinkedList<>();

        MeterData_Req meterData_req;
        for(int i = 0 ; i < 1 ; i++){
            meterData_req = new MeterData_Req();
            meterData_req.setMeterId("0012345678");
            meterData_req.setMeterNo("1704101484");
            list.add(meterData_req);
        }

        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("meters",list);

        String string = JSONObject.toJSONString(dataMap);
        System.out.println(string);


    }

    /**7.11. 获取抄表结算数据*/
    private static void testBillingData(){
        List<BillingData_Req> list = new LinkedList<>();

        BillingData_Req billingData_req;
        for(int i = 0 ; i < 1 ; i++){
            billingData_req = new BillingData_Req();
            billingData_req.setMeterId("0012345678");
            billingData_req.setMeterNo("1704101484");
            billingData_req.setLastMRDate("2018-06-01 00:00:00");
            billingData_req.setCurrMRDate(simpleDateFormat.format(new Date()));
            billingData_req.setMrOrderId("1");
            list.add(billingData_req);
        }

        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("meters",list);

        String string = JSONObject.toJSONString(dataMap);
        System.out.println(string);


    }

    /**7.12. 获取抄表实时数据*/
    private static void testRealtimeData(){
        List<RealTimeData_Req> list = new LinkedList<>();

        RealTimeData_Req realTimeData_req;
        for(int i = 0 ; i < 1 ; i++){
            realTimeData_req = new RealTimeData_Req();
            realTimeData_req.setMeterId("0012345678");
            realTimeData_req.setMeterNo("1704101484");
            realTimeData_req.setBeginTime("2018-06-01 00:00:00");
            realTimeData_req.setEndTime(simpleDateFormat.format(new Date()));
            list.add(realTimeData_req);
        }

        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("meters",list);

        String string = JSONObject.toJSONString(dataMap);
        System.out.println(string);
    }

    /**7.13. 获取日用量数据*/
    private static void testDayUse(){
        List<DayUse_Req> list = new LinkedList<>();

        DayUse_Req dayUse_req;
        for(int i = 0 ; i < 1 ; i++){
            dayUse_req = new DayUse_Req();
            dayUse_req.setMeterId("0012345678");
            dayUse_req.setMeterNo("1704101484");
            dayUse_req.setBeginDate("2018-06-01 00:00:00");
            dayUse_req.setEndDate(simpleDateFormat.format(new Date()));
            list.add(dayUse_req);
        }

        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("meters",list);

        String string = JSONObject.toJSONString(dataMap);
        System.out.println(string);
    }

    private static void testRecharge(){
        Recharge recharge = new Recharge();
        recharge.setMeterId("0012345678");
        recharge.setTradeNo("00000001");
        recharge.setRechargeTime(simpleDateFormat.format(new Date()));
        recharge.setRechargeAmt("20");
        recharge.setFactoryCode("1221");

        System.out.println(JSON.toJSONString(recharge));
    }

    private static void testCancelRecharge(){
        CancelRecharge cancelRecharge = new CancelRecharge();
        cancelRecharge.setMeterId("0012345678");
        cancelRecharge.setTradeNo("00000002");
        cancelRecharge.setCancelAmt("20");
        cancelRecharge.setCancleTime(simpleDateFormat.format(new Date()));

        System.out.println(JSON.toJSONString(cancelRecharge));
    }

    private static void testChangeprice(){
        ChangePrice changePrice = new ChangePrice();
        changePrice.setMeterId("0012345678");
        changePrice.setModifyTime(simpleDateFormat.format(new Date()));
        changePrice.setPriceId("2");
        changePrice.setPriceVersion("1");
        changePrice.setPriceLadderNum("3");
//        changePrice.setBillingCycle();
        calendar.clear();
        calendar.set(2018,6,27,10,0);
        changePrice.setEffectiveDate(simpleDateFormat.format(calendar.getTime()));
        changePrice.setCycleStartDate(simpleDateFormat.format(calendar.getTime()));
        changePrice.setPrice0("2.4");
        changePrice.setPrice1("3.6");
        changePrice.setPrice2("4.8");
        changePrice.setLevel1("12");
        changePrice.setLevel2("24");

        System.out.println(JSON.toJSONString(changePrice));
    }

    private static void testBatchChangePrice(){
        BatchChangePrice batchChangePrice = new BatchChangePrice();
        batchChangePrice.setOldPriceId("2");
        batchChangePrice.setOldPriceVersion("1");
        batchChangePrice.setPriceId("3");
        batchChangePrice.setPriceVersion("1");
        batchChangePrice.setPriceLadderNum("5");
        calendar.clear();
        calendar.set(2018,6,27,10,0);
        batchChangePrice.setCycleStartDate(simpleDateFormat.format(calendar.getTime()));
        batchChangePrice.setEffectiveDate(simpleDateFormat.format(calendar.getTime()));
        batchChangePrice.setPrice0("1.3");
        batchChangePrice.setPrice1("2.6");
        batchChangePrice.setPrice2("3.9");
        batchChangePrice.setPrice3("5.2");
        batchChangePrice.setPrice4("6.5");
        batchChangePrice.setLevel1("10");
        batchChangePrice.setLevel2("20");
        batchChangePrice.setLevel3("30");
        batchChangePrice.setLevel4("40");
        batchChangePrice.setOrgId("1");

        System.out.println(JSON.toJSONString(batchChangePrice));

    }

    private static void testCloseValve(){
        CloseValve closeValve = new CloseValve();
        closeValve.setMeterId("0012345678");
        closeValve.setFactoryCode("1221");

        System.out.println(JSON.toJSONString(closeValve));
    }

    private static void testOpenValve(){
        OpenValve openValve = new OpenValve();
        openValve.setMeterId("0012345678");
        openValve.setMeterId("1221");

        System.out.println(JSON.toJSONString(openValve));
    }





}
